<template>
  <div class="_wz_cent_main _wz_learningGarden">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form ref="formSearch" :model="formDataSearch" label-position="right" :label-width="120" inline>
        <FormItem label="文章标题">
          <i-input v-model="formDataSearch.newsTitle" placeholder="请填写文章标题" clearable />
        </FormItem>
        <FormItem label="副标题">
          <i-input v-model="formDataSearch.newsSub" placeholder="请填写副标题" clearable />
        </FormItem>
        <FormItem label="文章内容" v-if="searchType">
          <i-input v-model="formDataSearch.newsContent" placeholder="请填写文章内容" clearable />
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true" style="height: 100%;">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer title="查看详情" v-model="learningGardenSeeType" width="1000" :draggable="true">
      <learningGardenSee v-if="learningGardenSeeType" :selectData="selectData"></learningGardenSee>
    </Drawer>


  </div>
</template>
<script>

import learningGardenSee from "./learningGardenSee";
import wzTbale from "../../components/table/table";

export default {
  name:'learningGarden',
  props: ['newsType'],//接收来自父组件的数据
  components: {
    learningGardenSee,//查看
    wzTbale,//列表
  },
  data() {
    return {
      searchType:false,
      learningGardenSeeType:false,
      formDataSearch: {newsType:this.newsType},//搜索表单数据
      selectData: {},
      tableData: {
        url: this.apiUrl.newsLearnArticleNewsLearnArticlePageList,//请求地址
        method: 'post',//请求方式
        where: {newsType:this.newsType},//搜索条件
        height: '100%',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '文章标题', minWidth: 200, key: 'newsTitle'},
          {title: '文章作者', minWidth: 160, key: 'newsAuthor'},
          {title: '副标题', minWidth: 160, key: 'newsSub'},
          {title: '创建时间', width: 160, key: 'createTime'},
          {
            title: '操作', fixed: 'right', width: 120,
            render: (h, params) => {
              var operationButtons = [];
              //查看
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row))
                      this.learningGardenSeeType = true
                    }
                  }
                }, "查看")
              )
              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },
    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态

  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_learningGarden {
  padding: 0px!important;
  height: 100%;
  display: flex;
  flex-direction: column;

  .ivu-card-body {
    height: calc(100% - 51px);
  }
}
</style>
